class GUIScape

This class describes the table (grid) that holds the GUIPatches. Other than that, its only tasks are to propagate update calls to the patches and calculate a shade for patch backgrounds.

Public Class Methods

new(scape) click to toggle source

Initialize a table that will mimic the scape by creating a set of GUIPatches laid out in the same manner as they are in the scape.

Calls superclass method
# File lib/gui_scape.rb, line 12
def initialize(scape)
  super(scape.width, scape.height, true)

  set_row_spacings(5)
  set_column_spacings(5)

  # Need to find the max and min resource carrying capacity so as to shade patches correctly
  max_ccs, min_ccs = {}, {}
  scape.patches.each do |col|
    col.each do |patch|
      patch.resources.each do |resource|
        cc = resource.carrying_capacity

        max_cc = max_ccs.fetch(resource.name, 0)
        max_cc = [max_cc, cc].max
        max_ccs[resource.name] = max_cc

        min_cc = min_ccs.fetch(resource.name, 9999) # TODO: Ruby got no const for max int
        min_cc = [min_cc, cc].min
        min_ccs[resource.name] = min_cc
      end
    end
  end

  scape.patches.each_with_index do |col, x|
    col.each_with_index do |patch, y|
      # Calculate shade factor
      # This is just the relative carrying capacity of the patch to other patches
      resources = patch.resources
      shade = resources.reduce(0) do |m, r|
        min = min_ccs[r.name]
        range = max_ccs[r.name] - min
        m + (r.carrying_capacity - min) / range
      end / resources.size

      # Finally, add patch to table
      attach_defaults(GUIPatch.new(patch, shade), x, x + 1, y, y + 1)
    end
  end
end

Public Instance Methods

config_update(conf) click to toggle source

Propagates configuation updates on to the GUIPatches

# File lib/gui_scape.rb, line 61
def config_update(conf)
  each { |child| child.config_update(conf)}
end
update() click to toggle source

Propagates update calls on to the GUIPatches

# File lib/gui_scape.rb, line 55
def update
  each { |child| child.update }
end